/**
 * 
 */
package com.nstar.orderexpress.bmo.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.nstar.common.BaseException;
import com.nstar.common.DAOException;
import com.nstar.common.DbException;
import com.nstar.model.orderexpress.Menu2Rest;
import com.nstar.model.orderexpress.OrderInfo;
import com.nstar.model.orderexpress.OrderInfoExp;
import com.nstar.model.orderexpress.OrderMenu;
import com.nstar.orderexpress.bmo.OrderInfoManager;
import com.nstar.orderexpress.dao.OrderInfoDAO;
import com.nstar.orderexpress.dao.UtilityDAO;

/**
 * @author Administrator
 *
 */
public class OrderInfoManagerImpl implements OrderInfoManager {
	private static Logger logger = Logger.getLogger(OrderInfoManagerImpl.class.getName());
	
	
	private OrderInfoDAO orderInfoDAO;
	private UtilityDAO utilityDAO;
	
	
	
	public OrderInfoDAO getOrderInfoDAO() {
		return orderInfoDAO;
	}

	public void setOrderInfoDAO(OrderInfoDAO orderInfoDAO) {
		this.orderInfoDAO = orderInfoDAO;
	}	
	
	public UtilityDAO getUtilityDAO() {
		return utilityDAO;
	}

	public void setUtilityDAO(UtilityDAO utilityDAO) {
		this.utilityDAO = utilityDAO;
	}

	public List findOrderMenus(String filter, String orderby, int start, int end)
			throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.findOrderMenus(filter, orderby, start, end);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public List findOrderMenus(String areaId, String restId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.findOrderMenus(areaId, restId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public List findOrderMenus(String areaId, String restId, String foodTypeId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.findOrderMenus(areaId, restId, foodTypeId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public OrderInfo[] findOrderInfo(String filter, String orderby, int start, int end) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return (OrderInfo[])orderInfoDAO.findOrderInfo(filter, orderby, start, end).toArray(new OrderInfo[0]);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}
	
	public OrderInfo[] findOrderInfo(String areaId, String orderId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return (OrderInfo[])orderInfoDAO.findOrderInfo(areaId, orderId).toArray(new OrderInfo[0]);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}
	

	public OrderInfoExp[] findOrderInfoExp(String orderId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return (OrderInfoExp[])orderInfoDAO.findOrderInfoExp(orderId).toArray(new OrderInfoExp[0]);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public OrderInfoExp[] findOrderInfoExp(String orderId, String itemSpecId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return (OrderInfoExp[])orderInfoDAO.findOrderInfoExp(orderId, itemSpecId).toArray(new OrderInfoExp[0]);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}
	
	public OrderInfoExp findOrderInfoExpSeqOne(String orderId, String itemSpecId) throws BaseException{
		OrderInfoExp[] oies = findOrderInfoExp(orderId, itemSpecId);
        return (oies != null && oies.length>0)?oies[0]:null;
	}
	
	public List findOrderMenu2Rest(String filter, String orderby, int start, int end) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.findOrderMenu2Rest(filter, orderby, start, end);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public List findOrderMenu2Rest(String menuId, String areaId, String restId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.findOrderMenu2Rest(menuId, areaId, restId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}
	

	public int deleteMenu2Rest(Menu2Rest mr) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.deleteMenu2Rest(mr);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int deleteMenu2Rest(String menuId, String areaId, String restId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.deleteMenu2Rest(menuId, areaId, restId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int deleteOrderInfo(String areaId, String orderId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.deleteOrderInfo(areaId, orderId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int deleteOrderInfoExp(String orderId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.deleteOrderInfoExp(orderId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int deleteOrderInfoExp(String orderId, String itemSpecId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.deleteOrderInfoExp(orderId, itemSpecId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int deleteOrderMenus(String menuId) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.deleteOrderInfoExp(menuId);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int insertMenu2Rest(Menu2Rest mr) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.insertMenu2Rest(mr);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int insertOrderInfo(OrderInfo oi) throws BaseException {
		// TODO Auto-generated method stub
		try {
			oi.setOrderId(utilityDAO.formatSequence("order_info_seq", "yyyyMMdd", 15));
            return orderInfoDAO.insertOrderInfo(oi);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int insertOrderInfoExp(OrderInfoExp oie) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.insertOrderInfoExp(oie);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int insertOrderInfoExp(final String orderId,
			  final String itemSpecId,
			  final String newVal,
			  final String oldVal) throws BaseException{
		try {
            return orderInfoDAO.insertOrderInfoExp(orderId,
            			itemSpecId,
            			newVal,
            			oldVal);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }		
	}
	
	public int insertOrderMenus(OrderMenu om) throws BaseException {
		// TODO Auto-generated method stub
		try {
			String menuId = utilityDAO.formatSequence("order_menu_seq", "yyyyMMdd", 15);
			om.setMenuId(menuId);
            return orderInfoDAO.insertOrderMenus(om);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int updateMenu2Rest(Menu2Rest mr) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.updateMenu2Rest(mr);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int updateOrderInfo(OrderInfo oi) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.updateOrderInfo(oi);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int updateOrderInfoExp(OrderInfoExp oie) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.updateOrderInfoExp(oie);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}

	public int updateOrderMenus(OrderMenu om) throws BaseException {
		// TODO Auto-generated method stub
		try {
            return orderInfoDAO.updateOrderMenus(om);
        }
        catch (DAOException ex) {
            throw new DbException(BaseException.SUBSYSTEM_ORDER_INFO,
                                  BaseException.SIDE_BACKGROUND,
                                  ex);

        }
	}


}
